$(document).ready(function() {
    // set up the news accordion on the lower page
    $("#since").datepicker({
        changeMonth: true,
        changeYear: true
    });

    // create the image rotator
    setInterval("rotateImages()", 2000);
    $("#mainContent input:submit").button();
    $("li a:contains(Home)").addClass('current');
    $("select#category").change(get_faultlist);
    $("p#other").hide();
});
function rotateImages() {
    var oCurPhoto = $('#photoShow div.current');
    var oNxtPhoto = oCurPhoto.next();
    if (oNxtPhoto.length == 0)
        oNxtPhoto = $('#photoShow div:first');

    oCurPhoto.removeClass('current').addClass('previous');
    oNxtPhoto.css({
        opacity: 0.0
    }).addClass('current').animate({
        opacity: 1.0
    }, 1000,
    function() {
        oCurPhoto.removeClass('previous');
    });
}

function get_faultlist(){
    var category = $("select#category option:selected").text();

    if(category!="- Select One -"){
      //  alert(category);
        data="category="+category;
        $.ajax({
            type: 'POST',
            url: base_url() + 'customer/get_fault_ajax',
            data: data,
            datatype: "json",
            success : function (result) {
                var data=$.parseJSON(result);
                var html="";
                for(i=0;i<data.length;i++)
                {

                  html=html+'<input name="faultid" type="radio" title='+data[i].title+' value=' +data[i].faultid+'>'+data[i].description+'<br/>';
                }
               // alert(html);
                $("p#fault").html(html);
                $("p#fault :radio").click(other);
                


 
            }
        });
    }
   
}
function other()
{
    //$("p#other").slideToggle("slow");
    var other =this.title;
   if(other=="other"){
       $("p#other").slideDown("slow");
    }
   else
       $("p#other").slideUp("slow");
   //alert(other);
}
function highlight(evt)
{
    $("#boardCompare tbody tr").removeClass("clickrow");
    $(this).addClass("clickrow");
    var id=$(this).html();
    id=id.substring(id.indexOf(">")+1,id.indexOf("</td>"));
    // alert(id);
    data="categfory="+category;
    $.ajax({
        type: 'POST',
        url: base_url() + 'de/result_ajax',
        data: id,
        datatype: "json",
        success : function (result) {
            var data=$.parseJSON(result);
            // alert(data.result);

            var html="Application ID: "+data.Id+"<br/><br/>"+
            "First Name: "+data.FirstName+"<br/><br/>"+
            "Last Name: "+data.LastName+"<br/><br/>"+
            "Gender: "+data.Gender+"<br/><br/>"+
            "Permanent Address: "+data.PermAdd+"<br/><br/>"+
            "Present Address: "+data.PresAdd+"<br/><br/>"+
            "Email: "+data.Email+"<br/><br/>"+
            "DateOfBirth: "+data.Birthday+"<br/><br/>"+
            "Already Customer: "+data.AlreadyCustomer+"<br/><br/>"+
            "Result: "+data.result+"<br/><br/>";
            if(data.result=="Negative")
                html=html+"Cause: "+data.cause;
            $("div.detail div:first").html(html);
            var hidden='<input type="hidden" name="id" value='+data.Id+" />";
            if(data.result=="Negative")
                $('form#issue').remove();
            else
                $('form#reject').remove();


            $("div.process form").prepend(hidden);
            $("div.detail").slideDown("slow");



        }
    });
}

